package com.yongcheon.starhealthcare.main.drawer;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yongcheon.starhealthcare.R;

import java.util.ArrayList;


/**
 * Created by yongcheon on 2015-02-05.
 */
public class DrawerListAdapter extends BaseAdapter {
    private Context context;
    private int layout;
    private LayoutInflater Inflater;
    private ArrayList<DrawListItem> drawListItems;

    public DrawerListAdapter(Context context, int alayout, ArrayList<DrawListItem> drawListItems){
        this.context = context;
        this.layout = alayout;
        this.Inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.drawListItems = drawListItems;
    }

    @Override
    public int getCount() {
        return drawListItems.size();
    }

    @Override
    public Object getItem(int position) {
        return drawListItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = Inflater.inflate(layout, parent, false);
        }
        RelativeLayout relativeLayout = (RelativeLayout)convertView.findViewById(R.id.draw_listItem);
        ImageView imgView = (ImageView)convertView.findViewById(R.id.list_img);
        TextView textView = (TextView)convertView.findViewById(R.id.list_text);

        DrawListItem drawListItem = drawListItems.get(position);
        if(drawListItem.getBg() != null) {
            relativeLayout.setBackground(drawListItem.getBg());
            relativeLayout.getLayoutParams().height = drawListItem.getHeight();
            relativeLayout.getLayoutParams().width = RelativeLayout.LayoutParams.MATCH_PARENT;
            relativeLayout.setLayoutParams(relativeLayout.getLayoutParams());
        }
        imgView.setImageDrawable(drawListItem.getIcon());
        textView.setText(drawListItem.getText());
        return convertView;
    }
}
